package com.biz.primus.ms.commodity.dao.repository.product;


import com.biz.primus.ms.base.jpa.repository.CommonJpaRepository;
import com.biz.primus.ms.commodity.dao.po.MnsProduct;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @author zhangcheng
 * @date 2017/1/5
 * @reviewer
 * @see
 */
public interface MnsProductRepository extends CommonJpaRepository<MnsProduct, Long>, MnsProductDao{

    @Query("FROM MnsProduct p WHERE p.matnr = ?1")
    MnsProduct findBySku(String sku);

    @Query("FROM MnsProduct p ORDER BY p.createTimestamp DESC")
    Page<MnsProduct> findAllByCreateTime(Pageable pageable);

    @Query("FROM MnsProduct p WHERE p.matnr LIKE %:productCode% ORDER BY p.createTimestamp DESC")
    Page<MnsProduct> findBySkuLike(@Param("productCode") String productCode, Pageable pageable);

    @Query("FROM MnsProduct p WHERE p.maktx LIKE %:productName% ORDER BY p.createTimestamp DESC")
    Page<MnsProduct> findByNameLike(@Param("productName") String productName, Pageable pageable);

}
